<!--
* description: 双日期时间选择器(禁用当日之前的日期)
* author: lanrj
* createdDate: 2020-03-11
-->
<template>
  <el-col :span="span" id="crmdtdatepicker">
    <lableName
      :validrule="validrule"
      :curLabelName="curLabelName"
      :isShowLabel="isShowLabel"
      :isRequire="isRequire"
    ></lableName>
    <el-date-picker
      v-model="modelCode"
      :type="dateType"
      range-separator="至"
      :picker-options="pickerOptions"
      :default-time="defaultTime"
      start-placeholder="开始日期"
      end-placeholder="结束日期"
      :value-format="format"
      @change="sendCode"
      clearable
      :disabled="disabled"
      style="width:68%;"
      unlink-panels
    ></el-date-picker>
    <validateFormate :curLabelName="curLabelName" :validrule="validrule"></validateFormate>
  </el-col>
</template>

<script>
import { inputMixins } from "@/components/mixins/inputMixins";
export default {
  name: "crmdtDatePicker",
  mixins: [inputMixins],
  components: {
    lableName: () => import("@/components/lableName"), //标题溢出样式组件
    validateFormate: () => import("@/components/validateFormate") //校验提示样式组件
  },
  props: {
    dateType: { type: String, default: "datetimerange" },
    format: { type: String, default: "yyyy-MM-dd HH:mm:ss" },
    dateOptionsType: { type: String, default: "" },
    span: {
      type: Number,
      default: function() {
        return 6;
      }
    }
  },
  watch: {
    modelCode(val) {
      debugger;
      let str = this.codeField;
      if (str) {
        var arr = str.split(",");
        this.$parent.$parent.$parent.formField[arr[0]] = val[0];
        this.$parent.$parent.$parent.formField[arr[1]] = val[1];
      }
    }
  },
  watch: {
    modelCode(val) {
      debugger;
      let str = this.codeField;
      if (str) {
        var arr = str.split(",");
        this.$crmcf.__getParent(this, "formField", function(formField) {
          if (val != null) {
            formField[arr[0]] = val[0];
            formField[arr[1]] = val[1];
          } else {
            formField[arr[0]] = "";
            formField[arr[1]] = "";
          }
        });
      }
    }
  },
  data() {
    return {
      pickerOptions: {
        disabledDate(time) {
          return time.getTime() < Date.now() - 8.64e7||time.getTime() > Date.now();
        }
      },
      // defaultTime: ["12:00:00", "13:00:00"]  //选择日期后默认的时分秒
    };
  },
  mounted(){
    let that=this;
    this.pickerOptions={
      disabledDate(time) {
        return time.getTime() < Date.now() - 8.64e7||time.getTime() > new Date(that.getDate()).getTime();
      }
    }
  },
  methods:{
    //获取当前时间
    getDate(){
      var myDate = new Date();
        //获取当前年
      var year = myDate.getFullYear();
      //获取当前月
      var month = myDate.getMonth() + 1;
        //获取当前日
        var date = myDate.getDate();
        var h = myDate.getHours(); //获取当前小时数(0-23)
        var m = myDate.getMinutes(); //获取当前分钟数(0-59)
        var s = myDate.getSeconds();
      //获取当前时间
      return year + '-' + this.conver(month) + "-" + this.conver(date) + " 23:59:59"
      // return year + '-' + this.conver(month) + "-" + this.conver(date) + " " + this.conver(h) + ':' + this.conver(m) + ":" + this.conver(s);
    },
    //日期时间处理
    conver(s) {
      return s < 10 ? '0' + s : s;
    },
  }
};
</script>
